<?php 
// 数据库抽象层
// core/Database.php
class Database {
    protected $pdo;
    
    public function __construct($config) {
        $dsn = "mysql:host={$config['host']};dbname={$config['database']};charset={$config['charset']}";
        $this->pdo = new PDO($dsn, $config['username'], $config['password'], $config['options'] ?? []);
    }
    
    public function query($sql, $params = []) {
        $stmt = $this->pdo->prepare($sql);
        $stmt->execute($params);
        return $stmt;
    }
    
    public function table($table) {
        return new QueryBuilder($this, $table);
    }
}

// 查询构建器
class QueryBuilder {
    protected $db;
    protected $table;
    protected $conditions = [];
    protected $fields = ['*'];
    
    public function __construct(Database $db, $table) {
        $this->db = $db;
        $this->table = $table;
    }
    
    public function where($field, $operator, $value) {
        $this->conditions[] = [$field, $operator, $value];
        return $this;
    }
    
    public function get() {
        $sql = "SELECT " . implode(', ', $this->fields) . " FROM {$this->table}";
        
        if (!empty($this->conditions)) {
            $whereClauses = [];
            $params = [];
            
            foreach ($this->conditions as $condition) {
                list($field, $operator, $value) = $condition;
                $whereClauses[] = "{$field} {$operator} ?";
                $params[] = $value;
            }
            
            $sql .= " WHERE " . implode(' AND ', $whereClauses);
        }
        
        $stmt = $this->db->query($sql, $params);
        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }
    
    // 更多方法: insert, update, delete, join等
}